#include <LengthUnit.h>
#include <sstream>

const unsigned int MILE_TO_YARD    = 1760;
const unsigned int YARD_TO_FEET    = 3;
const unsigned int BASE_UNIT_VALUE = 1;

const LengthUnit* LengthUnit::getMileInstance()
{
    static LengthUnit mile("MILE", MILE_TO_YARD, YARD);
    return &mile;
}

const LengthUnit* LengthUnit::getYardInstance()
{
    static LengthUnit yard("YARD", YARD_TO_FEET, FEET);
    return &yard;
}

const LengthUnit* LengthUnit::getFeetInstance()
{
    static LengthUnit feet("FEET", BASE_UNIT_VALUE, 0);
    return &feet;
}

LengthUnit::LengthUnit(const std::string& name, unsigned int factor, const LengthUnit* referenceUnit)
    : baseUnitConversion(name, factor, referenceUnit)
{
}

unsigned int LengthUnit::toBase() const
{
    return baseUnitConversion.toBase();
}

std::string LengthUnit::outputString(unsigned int amountInBase) const
{
    std::stringstream os;
    baseUnitConversion.outputString(os, MILE, amountInBase);
    return os.str();
}
